import axios from '@/utils/request'
export default {
  ContentVisit: {
    list: {
      disabled_actions: ['lines', 'new'],
      list_filter: {
        'content.id': () => {
          return axios
            .get(`/manage/contents`)
            .then(res =>
              Object.assign({ __label: '文章' },
                ...res.data.map(v => { return { [v.id]: v.title } })))
        }
      },
      list_display: [
        {
          property: 'user',
          label: '阅读者',
          component: {
            props: ['data'],
            data() {
              return {
                staff: ''
              }
            },
            created() {
              this.axios.get(`/manage/staffs`, {
                params: {
                  '@filter': `entity.getUser().getId() == ${this.data.id}`
                }
              }).then((res) => {
                if (res.data.length > 0) {
                  this.staff = res.data[0]
                }
              })
            },
            render(h) {
              if (this.staff === '') {
                return <div>{this.data.__toString}(游客用户)</div>
              } else {
                return <div>{this.staff.store.__toString}:{this.staff.name}</div>
              }
            }
          }
        },
        'content',
        'createdTime'
      ]
    },
    form: {
      fields: []
    }
  }
}

